from . import CrystalLib
from . import cfg
import random as rd

# 2024 01 03
class MapObject(object):
    __slots__ = ('mtype', 'addon', 'void_t')
    def __init__(self, mtype : int, addon : int, void_t: int = 0) -> None:
        self.mtype = mtype
        self.addon = addon
        self.void_t: int = void_t

# mapobject.void_t
MVT_NULL  = 0
MVT_SLIME = 1
MVT_FIRE  = 2
MVT_JUMP  = 3

def reLoad_bedwar_1():
    Map : list[list[MapObject]] = []
    for row in range(15):
        li = []
        for column in range(20):
            if cfg.map_g_isVoid(row, column):
                li.append(MapObject(CrystalLib.Void, 0))
            else:
                i = rd.randint(0, 100)
                if i < cfg.map_g_void_prob():
                    li.append(MapObject(CrystalLib.Void, 0))
                else:
                    i = rd.randint(0, 100)
                    if i < cfg.map_g_soft_prob():
                        li.append(MapObject(CrystalLib.Soft, 0))
                    else:
                        li.append(MapObject(CrystalLib.Hard, 0))
        Map.append(li)
    return Map

def get_void_t():
    if rd.randint(0,100) < 80:
        return MVT_NULL
    else:
        return rd.choice((MVT_SLIME, MVT_FIRE))

def get_soft():
    if rd.randint(0, 100) < 60:
        return MapObject(CrystalLib.Soft, 0)
    else:
        return MapObject(CrystalLib.Void, 0, get_void_t())
def reLoad_bedwar_0():
    Map = [[get_soft() for i in range(20)] for j in range(15)]
    for i in range(0, 10):
        for j in range(0,5):
            x, y = rd.randint(0, 1), rd.randint(0, 2)
            Map[j*3+y][i*2+x] = MapObject(CrystalLib.Hard, 0)
    
    for i in range(2, 5):
        for j in range(2, 5):
            Map[i][j] = MapObject(CrystalLib.Void, 0)
    for i in range(10, 13):
        for j in range(15, 18):
            Map[i][j] = MapObject(CrystalLib.Void, 0)
    return Map

_version = 'Maplib v2.0 - Release'
_version = 'Maplib v3 - Release' # birthplace is VOID
_version = 'Maplib v4' # map: int -> class <MapObject>
_version = 'Maplib v4.1' #1.15 add mapobject.void_t
CrystalLib.printm(f'Loading mod: {_version}')
def inits():
    CrystalLib.printm('地图加载器成功初始化。')
